﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	[TestClass]
	public class Generator_FixedBytes_A51_Test
	{
		#region tests

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram01()
		{
			Telegram telegram = CreateA51_Telegram01();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x10, 0x7A, 0x01, 0x7B, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram02()
		{
			Telegram telegram = CreateA51_Telegram02();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x09, 0x09, 0x68, 0x28, 0x01, 0x05, 0x02, 0x14, 0x1E, 0x08, 0x01, 0x22, 0x8D, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram03()
		{
			Telegram telegram = CreateA51_Telegram03();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x09, 0x09, 0x68, 0x73, 0x01, 0x05, 0x02, 0x20, 0x09, 0x00, 0x02, 0x00, 0xA6, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram04()
		{
			Telegram telegram = CreateA51_Telegram04();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x09, 0x09, 0x68, 0x73, 0x02, 0x05, 0x02, 0x20, 0x09, 0x00, 0x02, 0x00, 0xA7, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram05()
		{
			Telegram telegram = CreateA51_Telegram05();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x0E, 0x0E, 0x68, 0xF3, 0x01, 0x05, 0x02, 0x14, 0x1E, 0x08, 0x01, 0x22, 0x03, 0x56, 0x21, 0x43, 0xF5, 0x0A, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram06()
		{
			Telegram telegram = CreateA51_Telegram06();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x10, 0x20, 0x02, 0x22, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram07()
		{
			Telegram telegram = CreateA51_Telegram07();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x09, 0x09, 0x68, 0x00, 0x01, 0x05, 0x03, 0x14, 0x1E, 0x08, 0x01, 0x22, 0x66, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram08()
		{
			Telegram telegram = CreateA51_Telegram08();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x09, 0x09, 0x68, 0x53, 0x01, 0x05, 0x03, 0x14, 0x1E, 0x08, 0x01, 0x22, 0xB9, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram09()
		{
			Telegram telegram = CreateA51_Telegram09();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x10, 0x5A, 0x02, 0x5C, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram10()
		{
			Telegram telegram = CreateA51_Telegram10();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x10, 0x00, 0x01, 0x01, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram11()
		{
			Telegram telegram = CreateA51_Telegram11();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x09, 0x09, 0x68, 0x08, 0x02, 0x05, 0x03, 0x20, 0x09, 0x00, 0x02, 0x00, 0x3D, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test_A51_Telegram12()
		{
			Telegram telegram = CreateA51_Telegram12();

			IGeneratorParser generatorParser = Helpers.GetGeneratorParser();
			byte[] telegramBytes = generatorParser.GenerateTelegramBytes(telegram);

			byte[] expectedBytes = new byte[] { 0x68, 0x0E, 0x0E, 0x68, 0x80, 0x01, 0x05, 0x03, 0x20, 0x09, 0x00, 0x02, 0x00, 0x03, 0x56, 0x21, 0x43, 0xF5, 0x66, 0x16 };
			Assert.IsTrue(Helpers.Equals2ByteArrays(telegramBytes, expectedBytes));
		}

		#endregion tests

		#region static helpers

		private static Telegram CreateA51_Telegram01()
		{
			const byte address = 0x01;

			Telegram_Calling telegram = new Telegram_Calling(eDirection.RCT_to_ACE, address, eTelegramFunction_Calling.REQ_NDAT, true, true);

			return telegram;
		}

		private static Telegram CreateA51_Telegram02()
		{
			ReportType_Intrusion reportType = new ReportType_Intrusion(true, eReportSubType_Intrusion.Burglary);
			UserData_02_StatusChangeReport2Confirm userData02 = new UserData_02_StatusChangeReport2Confirm(0x14, 0x1E, 0x08, eAddressExtension_1.Input, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData02);

			const byte address = 0x01;
			Telegram_Returning_RESPOND_NDAT telegram = new Telegram_Returning_RESPOND_NDAT(eDirection.RCT_to_ACE, address, true, false, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram03()
		{
			ReportType_General reportType = new ReportType_General(true, eReportSubType_General.Message);
			UserData_02_StatusChangeReport2Confirm userData02 = new UserData_02_StatusChangeReport2Confirm(0x20, 0x09, 0x00, eAddressExtension_1.Output, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData02);

			const byte address = 0x01;
			Telegram_Calling_SEND_NDAT telegram = new Telegram_Calling_SEND_NDAT(eDirection.RCT_to_ACE, address, true, true, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram04()
		{
			ReportType_General reportType = new ReportType_General(true, eReportSubType_General.Message);
			UserData_02_StatusChangeReport2Confirm userData02 = new UserData_02_StatusChangeReport2Confirm(0x20, 0x09, 0x00, eAddressExtension_1.Output, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData02);

			const byte address = 0x02;
			Telegram_Calling_SEND_NDAT telegram = new Telegram_Calling_SEND_NDAT(eDirection.RCT_to_ACE, address, true, true, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram05()
		{
			ReportType_Intrusion reportType = new ReportType_Intrusion(true, eReportSubType_Intrusion.Burglary);
			UserData_02_StatusChangeReport2Confirm userData02 = new UserData_02_StatusChangeReport2Confirm(0x14, 0x1E, 0x08, eAddressExtension_1.Input, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData02);

			UserData_56_IdentificationNumber userData56 = new UserData_56_IdentificationNumber("12345");
			userDataColl.Add(userData56);

			const byte address = 0x01;
			Telegram_Calling_SEND_NDAT telegram = new Telegram_Calling_SEND_NDAT(eDirection.ATE_to_RCT, address, true, true, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram06()
		{
			Telegram_Returning telegram = new Telegram_Returning(eDirection.RCT_to_ACE, 0x02, eTelegramFunction_Returning.CONFIRM_ACK, true, false);

			return telegram;
		}

		private static Telegram CreateA51_Telegram07()
		{
			ReportType_Intrusion reportType = new ReportType_Intrusion(true, eReportSubType_Intrusion.Burglary);
			UserData_03_StatusChangeConfirm userData03 = new UserData_03_StatusChangeConfirm(0x14, 0x1E, 0x08, eAddressExtension_1.Input, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData03);
						
			const byte address = 0x01;
			Telegram_Returning_CONFIRM_ACK telegram = new Telegram_Returning_CONFIRM_ACK(eDirection.RCT_to_ACE, address, false, false, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram08()
		{
			ReportType_Intrusion reportType = new ReportType_Intrusion(true, eReportSubType_Intrusion.Burglary);
			UserData_03_StatusChangeConfirm userData03 = new UserData_03_StatusChangeConfirm(0x14, 0x1E, 0x08, eAddressExtension_1.Input, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData03);

			const byte address = 0x01;
			Telegram_Calling_SEND_NDAT telegram = new Telegram_Calling_SEND_NDAT(eDirection.RCT_to_ACE, address, true, false, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram09()
		{
			const byte address = 0x02;

			Telegram_Calling telegram = new Telegram_Calling(eDirection.RCT_to_ACE, address, eTelegramFunction_Calling.REQ_NDAT, true, false);

			return telegram;
		}

		private static Telegram CreateA51_Telegram10()
		{
			Telegram_Returning telegram = new Telegram_Returning(eDirection.RCT_to_ACE, 0x01, eTelegramFunction_Returning.CONFIRM_ACK, false, false);

			return telegram;
		}

		private static Telegram CreateA51_Telegram11()
		{
			ReportType_General reportType = new ReportType_General(true, eReportSubType_General.Message);
			UserData_03_StatusChangeConfirm userData03 = new UserData_03_StatusChangeConfirm(0x20, 0x09, 0x00, eAddressExtension_1.Output, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData03);
						
			const byte address = 0x02;
			Telegram_Returning_RESPOND_NDAT telegram = new Telegram_Returning_RESPOND_NDAT(eDirection.RCT_to_ACE, address, false, false, userDataColl);

			return telegram;
		}

		private static Telegram CreateA51_Telegram12()
		{
			ReportType_General reportType = new ReportType_General(true, eReportSubType_General.Message);
			UserData_03_StatusChangeConfirm userData03 = new UserData_03_StatusChangeConfirm(0x20, 0x09, 0x00, eAddressExtension_1.Output, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData03);

			UserData_56_IdentificationNumber userData56 = new UserData_56_IdentificationNumber("12345");
			userDataColl.Add(userData56);
						
			const byte address = 0x01;
			Telegram_Returning_CONFIRM_ACK telegram = new Telegram_Returning_CONFIRM_ACK(eDirection.ATE_to_RCT, address, false, false, userDataColl);

			return telegram;
		}

		#endregion static helpers
	}
}
